<?php
/*
 * 系列
 */
class CollectionAction extends HomeAction{
    public function _initialize() {
        send_http_status(404);
        $this->display(C('ERROR_PAGE'));
        exit;       
        parent::_initialize();
    }
       //url路由访问到这里
    public function read($link){
        global $language_id;
//                var_dump($link == 'styawithus');die;
        $link = htmlspecialchars($link);;
        $where['url_path'] = $link;
        $where['language_id'] = $language_id;
        $info = M('collection')->where($where)->find();
        
        if(!$info){
            send_http_status(404);
            $this->display(C('ERROR_PAGE'));
            exit;
        }
        
        if($link == 'staywithus' || $link == 'spring-sale'){
              send_http_status(301);
              redirect('/');
              exit;
        }
        
        $data = array(
        'docTitle' => $info['collection_title'],
        );
        
        $collection_info = M('collection_items')
        ->where("img_language_id = ".$language_id." and collection_id=".$info['collection_id'])
        ->order('banner_id')->select();

        foreach($collection_info as $k=>$v){
            $v['pids'] = trim($v['pids'],',');
            $collection_info[$k]['ids'] = explode(',',$v['pids']);      
            $product_list[$k] = ProductModel::get_product_collection_list($collection_info[$k]['ids'],$language_id);
        }
        
        if(htmlspecialchars($link) == 'staywithus'){
            cookie('self_coupon', 'staywithus','expire=604800&path=/&domain='.APP_DOMAIN);
            $this->assign('target_blank', 1);
        }

        if(htmlspecialchars($link) == 'spring-sale'){
            cookie('self_coupon', 'spring25','expire=604800&path=/&domain='.APP_DOMAIN);
            $this->assign('target_blank', 1);
        }
        
        $this->assign('link',trim($link));
        $this->assign($data);
        $this->assign('info',$info);
        $this->assign('product_list',$product_list);
        $this->assign('collection_info',$collection_info);
        
        $this->display();
    }
  
}